﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>装试班关联到组</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style>
        .easyui-linkbutton{margin-left:20px;}
        table tr td{padding:0px 5px}
        .Btitle{background-color: #ddd; padding: 10px; margin: 5px 10px;}
    </style>
</head>
<body>
    <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td>分厂:</td>
                    <td>工区:</td>
                    <td>组:</td>
	    		</tr>
	    		<tr>
	    			<td><input id="selFactory" name="Factory" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
	    			<td><input id="selWorkCenter" name="WorkCenter" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
                    <td><input id="selTeam" name="Team" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
	    		</tr>
	    	</table>
	    </form>
        </div> 
    </div>

    <div class="panelSection">    
        <div class="easyui-panel " title="查询结果" style="padding:3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
        <table id="ShiftAndTeamRelation" style="height:240px;width: 100%" data-options="rownumbers:true"></table>
        </div>
      </div>
    <div class="panelSection" >
        <div class="easyui-panel " title="基本信息" style="padding:3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="EditorForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td>分厂:</td>
                    <td>工区:</td>
                    <td>班:</td>
                    <td>组:</td>
                    <td>班次:</td>
	    		</tr>
	    		<tr>
                    <td><input id="selFactory1" name="FACTORYID" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
                    <td><input id="selWorkCenter1" name="WORKCENTERID" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
	    			<td><input id="selShift" name="SHIFTID" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
                    <td><input id="selTeam1" name="TEAMID" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
                    <td><input id="selWorkShift"  name="WORKSHIFTID" class="easyui-combobox" style="width: 120px; height: 22px"data-options='editable:false'/></td>
	    		</tr>
	    	</table>
	    </form>
        </div>
	  </div>

     <div class="panelSection">    
        <div class="easyui-panel " title="人员信息" style="padding:3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <div style="float: left;padding-top: 43px;">
                <table id="tbEmployee" class="easyui-datagrid" style="width: 350px;height: 300px;"data-options="rownumbers:true"></table>
            </div>
            <div style="float: left;width:90px;padding-top: 57px;"> 
                <button class="easyui-linkbutton" onclick="page.removeEmployee()" data-options="" style="margin:100px 10px 60px;">移除&gt;&gt;</button>
                <button class="easyui-linkbutton" onclick="page.addEmployee()" data-options="" style="margin:0 10px;">&lt;&lt; 添加</button>
            </div>
            <div style="float: left;">
                <form id="employeeForm">
                    <table>
                        <tr class="divLabel">
                            <td>姓名：</td>
                            <td>员工号：</td>
                        </tr>
                        <tr>
                            <td><input id="Text1" class="easyui-textbox" name="FullName" style="width: 120px; height: 22px"/></td>
                            <td><input id="Text2" class="easyui-textbox" name="EmployeeName" style="width: 120px; height: 22px"/></td>
                            <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchEmployee()">搜索</a></td>
                        </tr>
                    </table>
                </form>
                <table id="ddEmployee" class="easyui-datagrid" style="width: 350px;height: 300px;"data-options="rownumbers:true"></table>
            </div>
        </div>
    </div>
    
    <div class="panelSection">    
        <div class="easyui-panel " title="按钮区域" style="padding:3px;width: 100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
             <a href="javascript:void(0)" onclick="page.CreateShiftAndTeamRelation()" class="easyui-linkbutton" data-options="width:120" style="margin: 10px 0 10px 20px;">新建</a>
             <a href="javascript:void(0)" onclick="page.BindTeamAndWorkshiftAndEmployee()" class="easyui-linkbutton" data-options="width:120"  style="margin: 10px 0 10px 20px;">保存</a>
        </div>
    </div>
     <!--信息提示区域-->
     <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script>
    //创建人：longb
    //日期：2022-07-19
    //描述：装试班次维护
    var page = {
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsZsTeamShiftHandler.ashx",
        init: function () {
            page.initPageData();
            page.bind();
        },
        initPageData: function () {
            page.post({ action: "InitPageData" }, true, function (res) {
                //绑定日历下拉框
                $("#selMakeCalendar").combobox({
                    valueField: 'MAKECALENDARID',
                    textField: 'MAKECALENDARNAME',
                    panelHeight: 200,
                    data: res.DBDataSet.dtMakeCalendar //下拉数据
                });
                //绑定班次下拉框
//                $("#selShift").combobox({
//                    valueField: 'SHIFTID',
//                    textField: 'SHIFTNAME',
//                    panelHeight: 200,
//                    data: res.DBDataSet.dtShift //下拉数据
//                });
                $("#selWorkShift").combobox({
                    valueField: 'WORKSHIFTID',
                    textField: 'WORKSHIFTNAME',
                    panelHeight: 200,
                    data: res.DBDataSet.dtWorkShift //下拉数据
                });
                //绑定工厂下拉框
                page.bindFactory('selFactory', res.DBDataSet.dtFactory, 'selWorkCenter');
                page.bindFactory('selFactory1', res.DBDataSet.dtFactory, 'selWorkCenter1');
            });
        },
        bindFactory: function (id, data, itemid) {
            $("#" + id).combobox({
                valueField: 'FACTORYID',
                textField: 'FACTORYNAME',
                panelHeight: 200,
                data: data, //下拉数据
                onSelect: function (record) {
                    if (record.FACTORYID !== "") {
                        page.bindWorkCenter(record.FACTORYID, itemid); //加载工区
                    }
                }
            });
        },
        //绑定工区
        bindWorkCenter: function (factoryId, itemid) {
            page.post({ action: "GetWorkCenter", factoryId: factoryId }, false, function (res) {
                if (res.Result) {
                    //绑定工区下拉框
                    $("#" + itemid).combobox({
                        valueField: 'WORKCENTERID',
                        textField: 'WORKCENTERNAME',
                        panelHeight: 200,
                        data: res.DBTable, //下拉数据
                        onSelect: function (record) {
                            //var ittemid = itemid == "selWorkCenter" ? "selTeam" : "selTeam1";
                            if (itemid == "selWorkCenter") {
                                page.bindTeam(record.WORKCENTERID,'',"selTeam");
                            }else{
                                page.bindShift(record.WORKCENTERID);
                            }
                        }
                    });
                }
            });
        },
        //绑定班组
        bindTeam: function (workcenterId,shiftId, ittemid) {
            page.post({ action: "GetTeam", workCenterId: workcenterId, shiftId: shiftId }, false, function (res) {
                if (res.Result) {
                    //绑定班组
                    $("#" + ittemid).combobox({
                        valueField: 'TEAMID',
                        textField: 'TEAMNAME',
                        panelHeight: 200,
                        data: res.DBTable, //下拉数据
                        onSelect: function (record) {
                            if (ittemid == "selTeam1") {
                                page.GetTeamEmployees(record.TEAMID);
                            }
                        }
                    });
                }
            });
        },
        bindShift: function (workcenterId) {
            page.post({ action: "GetShift", workCenterId: workcenterId }, false, function (res) {
                if (res.Result) {
                    //绑定班组
                    $("#selShift").combobox({
                        valueField: 'SHIFTID',
                        textField: 'SHIFTNAME',
                        panelHeight: 200,
                        data: res.DBTable, //下拉数据
                        onSelect: function (record) {
                            page.bindTeam('', record.SHIFTID, 'selTeam1');
                        }
                    });
                }
            });
        },
        //页面事件绑定
        bind: function () {
            $('#ShiftAndTeamRelation').datagrid({
                singleSelect: true,
                columns: [[
                 { field: 'FACTORYNAME', title: '分厂', width: 150 },
		         { field: 'WORKCENTERNAME', title: '工区（中心）', width: 180 },
                 { field: 'SHIFTNAME', title: '班', width: 120 },
                 { field: 'TEAMNAME', title: '组', width: 120 },
                 { field: 'WORKSHIFTNAME', title: '班次', width: 120 }
                ]],
                onSelect: function (index, row) {
                    $('#EditorForm').form('load', row);
                    page.GetTeamEmployees(row.TEAMID);
                }
            });

            var columns = [{ field: 'EMPLOYEEID', width: 50, checkbox: true }, { field: 'EMPLOYEENAME', title: '员工号', width: 150 }, { field: 'FULLNAME', title: '姓名', width: 150}]
            $('#tbEmployee').datagrid({ columns: [columns] });
            $('#ddEmployee').datagrid({ columns: [columns] });
        },
        //查询
        searchData: function () {
            clearMessage();
            page.GetApsShiftAndTeamRelation();
        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            page.bind();
            clearMessage();
        },
        //查询任务单信息
        GetApsShiftAndTeamRelation: function () {
            var frdata = $('#searchForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            var param = {
                action: "GetApsShiftAndTeamRelation",
                data: JSON.stringify([data])
            };
            page.post(param, true, function (res) {
                $('#ShiftAndTeamRelation').datagrid('loadData', res.DBTable);
            });
        },
        GetTeamEmployees: function (teamid) {
            var param = {
                action: "GetTeamEmployees",
                teamid: teamid
            };
            page.post(param, true, function (res) {
                $('#tbEmployee').datagrid('loadData', res.DBTable);
            });
        },
        //保存
        BindTeamAndWorkshiftAndEmployee: function () {
            var frdata = $('#EditorForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            if (data.TEAMID == "") { displayMessage('请选择班组，再进行保存', false); return; }
            if (data.WORKSHIFTID == "") { displayMessage('请选择班次，再进行保存', false); return; }
            var rows = $('#tbEmployee').datagrid('getRows');
            var param = {
                action: "BindTeamAndWorkshiftAndEmployee",
                data: JSON.stringify([data]),
                employees: JSON.stringify(rows)
            };
            page.post(param, true, function (res) {
                if (res.Result) {
                    page.GetApsShiftAndTeamRelation();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        CreateShiftAndTeamRelation: function () {
            $('#tbEmployee').datagrid('loadData', []);
            $('#EditorForm').form('clear');
        },
        //查询员工
        searchEmployee: function () {
            var frdata = $('#employeeForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            var param = {
                action: "GetEmployee",
                data: JSON.stringify([data])
            };
            page.post(param, true, function (res) {
                $('#ddEmployee').datagrid('loadData', res.DBTable);
            });
        },
        //移出
        removeEmployee: function () {
            var rows = $('#tbEmployee').datagrid('getChecked');
            if (rows.length == 0) { displayMessage('请勾选已关联人员信息，再进行移出操作', false); }
            $.each(rows, function (index, item) {
                var index1 = $('#tbEmployee').datagrid('getRowIndex', item);
                if (index1 != -1) {
                    $('#tbEmployee').datagrid('deleteRow', index);
                }
            })
        },
        //移入
        addEmployee: function () {
            var rowss = $('#ddEmployee').datagrid('getChecked');
            if (rowss.length == 0) { displayMessage('请勾选已关联人员信息，再进行移入操作', false); }
            var tbRows = $('#tbEmployee').datagrid('getRows');
            rowss.forEach(function (item) {
                var isExist = tbRows.some(function (i) {
                    return i.EMPLOYEEID === item.EMPLOYEEID
                })
                if (!isExist) {
                    $('#tbEmployee').datagrid('appendRow', item);
                }
            });
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
        },

        //post数据
        post: function (param, async, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    $(function () {
        page.init();
    });



</script>
